var exports = {};

exports.BASE_URL = "https://www.519151.com/";
exports.IMGPATH2 = exports.BASE_URL + "/Public/common/";
exports.IMGPATH = "../../images/";

exports.ajax = function (t) {
  var o = t.url,
    n = t.data,
    a = t.method,
    c = void 0 === a ? "POST" : a;
  return new Promise(function (t, a) {
    var r = exports.BASE_URL;
    wx.request({
      url: "".concat(r).concat(o),
      header: {
        "content-type": "application/json",
        'Cookie': 'PHPSESSID=hncarqeaabok3i7olfno6r638j; no_user_id=390d113e0b5e107e0322dbbc7c792c68'
      },
      method: c,
      dataType: "json",
      responseType: "text",
      data: n,
      success: function (e) {
        t(e.data);
      },
      fail: function (e) {
        a(e);
      }
    });
  }).catch(function (e) {
    console.log(e);
  });
};

exports.md5 = function (r) {
  function n(r, n) {
    return r << n | r >>> 32 - n;
  }

  function t(r, n) {
    var t, e, o, u, f;
    return o = 2147483648 & r, u = 2147483648 & n, f = (1073741823 & r) + (1073741823 & n),
      (t = 1073741824 & r) & (e = 1073741824 & n) ? 2147483648 ^ f ^ o ^ u : t | e ? 1073741824 & f ? 3221225472 ^ f ^ o ^ u : 1073741824 ^ f ^ o ^ u : f ^ o ^ u;
  }

  function e(r, e, o, u, f, i, a) {
    return r = t(r, t(t(function (r, n, t) {
      return r & n | ~r & t;
    }(e, o, u), f), a)), t(n(r, i), e);
  }

  function o(r, e, o, u, f, i, a) {
    return r = t(r, t(t(function (r, n, t) {
      return r & t | n & ~t;
    }(e, o, u), f), a)), t(n(r, i), e);
  }

  function u(r, e, o, u, f, i, a) {
    return r = t(r, t(t(function (r, n, t) {
      return r ^ n ^ t;
    }(e, o, u), f), a)), t(n(r, i), e);
  }

  function f(r, e, o, u, f, i, a) {
    return r = t(r, t(t(function (r, n, t) {
      return n ^ (r | ~t);
    }(e, o, u), f), a)), t(n(r, i), e);
  }

  function i(r) {
    var n, t = "",
      e = "";
    for (n = 0; n <= 3; n++) t += (e = "0" + (r >>> 8 * n & 255).toString(16)).substr(e.length - 2, 2);
    return t;
  }
  var a, c, C, g, h, d, s, l, m, v = Array();
  for (r = function (r) {
      r = r.replace(/\r\n/g, "\n");
      for (var n = "", t = 0; t < r.length; t++) {
        var e = r.charCodeAt(t);
        e < 128 ? n += String.fromCharCode(e) : e > 127 && e < 2048 ? (n += String.fromCharCode(e >> 6 | 192),
          n += String.fromCharCode(63 & e | 128)) : (n += String.fromCharCode(e >> 12 | 224),
          n += String.fromCharCode(e >> 6 & 63 | 128), n += String.fromCharCode(63 & e | 128));
      }
      return n;
    }(r), v = function (r) {
      var n, t = r.length,
        e = t + 8,
        o = 16 * ((e - e % 64) / 64 + 1),
        u = Array(o - 1),
        f = 0,
        i = 0;
      for (; i < t;) f = i % 4 * 8, u[n = (i - i % 4) / 4] = u[n] | r.charCodeAt(i) << f,
        i++;
      return f = i % 4 * 8, u[n = (i - i % 4) / 4] = u[n] | 128 << f, u[o - 2] = t << 3,
        u[o - 1] = t >>> 29, u;
    }(r), d = 1732584193, s = 4023233417, l = 2562383102, m = 271733878, a = 0; a < v.length; a += 16) c = d,
    C = s, g = l, h = m, d = e(d, s, l, m, v[a + 0], 7, 3614090360), m = e(m, d, s, l, v[a + 1], 12, 3905402710),
    l = e(l, m, d, s, v[a + 2], 17, 606105819), s = e(s, l, m, d, v[a + 3], 22, 3250441966),
    d = e(d, s, l, m, v[a + 4], 7, 4118548399), m = e(m, d, s, l, v[a + 5], 12, 1200080426),
    l = e(l, m, d, s, v[a + 6], 17, 2821735955), s = e(s, l, m, d, v[a + 7], 22, 4249261313),
    d = e(d, s, l, m, v[a + 8], 7, 1770035416), m = e(m, d, s, l, v[a + 9], 12, 2336552879),
    l = e(l, m, d, s, v[a + 10], 17, 4294925233), s = e(s, l, m, d, v[a + 11], 22, 2304563134),
    d = e(d, s, l, m, v[a + 12], 7, 1804603682), m = e(m, d, s, l, v[a + 13], 12, 4254626195),
    l = e(l, m, d, s, v[a + 14], 17, 2792965006), s = e(s, l, m, d, v[a + 15], 22, 1236535329),
    d = o(d, s, l, m, v[a + 1], 5, 4129170786), m = o(m, d, s, l, v[a + 6], 9, 3225465664),
    l = o(l, m, d, s, v[a + 11], 14, 643717713), s = o(s, l, m, d, v[a + 0], 20, 3921069994),
    d = o(d, s, l, m, v[a + 5], 5, 3593408605), m = o(m, d, s, l, v[a + 10], 9, 38016083),
    l = o(l, m, d, s, v[a + 15], 14, 3634488961), s = o(s, l, m, d, v[a + 4], 20, 3889429448),
    d = o(d, s, l, m, v[a + 9], 5, 568446438), m = o(m, d, s, l, v[a + 14], 9, 3275163606),
    l = o(l, m, d, s, v[a + 3], 14, 4107603335), s = o(s, l, m, d, v[a + 8], 20, 1163531501),
    d = o(d, s, l, m, v[a + 13], 5, 2850285829), m = o(m, d, s, l, v[a + 2], 9, 4243563512),
    l = o(l, m, d, s, v[a + 7], 14, 1735328473), s = o(s, l, m, d, v[a + 12], 20, 2368359562),
    d = u(d, s, l, m, v[a + 5], 4, 4294588738), m = u(m, d, s, l, v[a + 8], 11, 2272392833),
    l = u(l, m, d, s, v[a + 11], 16, 1839030562), s = u(s, l, m, d, v[a + 14], 23, 4259657740),
    d = u(d, s, l, m, v[a + 1], 4, 2763975236), m = u(m, d, s, l, v[a + 4], 11, 1272893353),
    l = u(l, m, d, s, v[a + 7], 16, 4139469664), s = u(s, l, m, d, v[a + 10], 23, 3200236656),
    d = u(d, s, l, m, v[a + 13], 4, 681279174), m = u(m, d, s, l, v[a + 0], 11, 3936430074),
    l = u(l, m, d, s, v[a + 3], 16, 3572445317), s = u(s, l, m, d, v[a + 6], 23, 76029189),
    d = u(d, s, l, m, v[a + 9], 4, 3654602809), m = u(m, d, s, l, v[a + 12], 11, 3873151461),
    l = u(l, m, d, s, v[a + 15], 16, 530742520), s = u(s, l, m, d, v[a + 2], 23, 3299628645),
    d = f(d, s, l, m, v[a + 0], 6, 4096336452), m = f(m, d, s, l, v[a + 7], 10, 1126891415),
    l = f(l, m, d, s, v[a + 14], 15, 2878612391), s = f(s, l, m, d, v[a + 5], 21, 4237533241),
    d = f(d, s, l, m, v[a + 12], 6, 1700485571), m = f(m, d, s, l, v[a + 3], 10, 2399980690),
    l = f(l, m, d, s, v[a + 10], 15, 4293915773), s = f(s, l, m, d, v[a + 1], 21, 2240044497),
    d = f(d, s, l, m, v[a + 8], 6, 1873313359), m = f(m, d, s, l, v[a + 15], 10, 4264355552),
    l = f(l, m, d, s, v[a + 6], 15, 2734768916), s = f(s, l, m, d, v[a + 13], 21, 1309151649),
    d = f(d, s, l, m, v[a + 4], 6, 4149444226), m = f(m, d, s, l, v[a + 11], 10, 3174756917),
    l = f(l, m, d, s, v[a + 2], 15, 718787259), s = f(s, l, m, d, v[a + 9], 21, 3951481745),
    d = t(d, c), s = t(s, C), l = t(l, g), m = t(m, h);
  return (i(d) + i(s) + i(l) + i(m)).toLowerCase();
};

exports.debounce = function (t, e) {
  var r;
  return function () {
    var n = this,
      o = arguments;
    clearTimeout(r), r = setTimeout(function () {
      t.apply(n, o);
    }, e);
  };
};

exports.excitationAdShow = function () {
  try {
    var t = wx.getStorageSync("systemInfo"),
      e = t || wx.getSystemInfoSync(),
      n = (e.system,
        e.platform),
      o = e.appName,
      a = e.version;
    if (t || wx.setStorage({
        key: "systemInfo",
        data: e,
        success: function (t) {},
        fail: function (t) {}
      }), "Douyin" !== o) return {
      appName: o,
      isAdShow: !1
    };
    if ("iOS" === n || "ios" === n || "devtools" === n) return console.log("是否展示广告", r(a, "10.7")), {
      appName: o,
      isAdShow: r(a, "10.7")
    };
    if ("android" === n) return console.log("是否展示广告", r(a, "10.3")), {
      appName: o,
      isAdShow: r(a, "10.3")
    };
  } catch (t) {
    console.log("获取系统信息失败");
  }
};

exports.objectToQueryString = function (t) {
  return Object.keys(t).map(function (e) {
    return "".concat(e, "=").concat(t[e]);
  }).join("&");
};

exports.getRandomNumberByRange = function (t, e) {
  return Math.floor(Math.random() * (e - t) + t);
};

exports.formatHeaderAgent = function (e) {
  var r = Date.now(),
    n = function () {
      for (var t = [], e = 0; e < 36; e++) t[e] = "0123456789abcdef".substr(Math.floor(16 * Math.random()), 1);
      return t[14] = "4", t[19] = "0123456789abcdef".substr(3 & t[19] | 8, 1), t[8] = t[13] = t[18] = t[23] = "-",
        t.join("");
    }();
  n = n.replace(/-/g, ""), console.log(n);
  var o = {
    appId: "42928896",
    timestamp: r,
    nonce: n,
    appVersion: "1.2.9"
  };
  bodyStr = JSON.stringify(e), bodyStr = bodyStr.replace(/\n/g, ""), bodyStr = bodyStr.replace(/\s+/g, "").trim(),
    o.ckstr = (0, t.md5)(bodyStr);
  var a = function (t) {
      var e = "";
      for (var r in t) e += r + "=" + t[r] + "&";
      return e.substring(0, e.length - 1);
    }(o) + "&7c3770997d33480e8d5cd4a73f7f7fe0",
    i = {
      appId: "42928896",
      sign: (0, t.md5)(a.toLowerCase()),
      timestamp: r,
      nonce: n,
      appVersion: "1.2.9"
    },
    c = JSON.stringify(i);
  return c = (c = c.replace(/\n/g, "")).replace(/\s+/g, "").trim();
};

module.exports = exports;